﻿using EasyNet.Componets.Core.Inject;
using EasyNet.Componets.Core.Zips;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EasyNet.Componets.Core.Utils
{
    /// <summary>
    /// Zip辅助类
    /// </summary>
    public static class ZipUtil
    {
        private static IZip _instance;

        private static IZip Instance
        {
            get
            {
                if (_instance != null)
                {
                    return _instance;
                }
                _instance = IoC.Resolve<IZip>();

                return _instance;
            }
        }

        public static void SetInstance(IZip instance)
        {
            _instance = instance;
        }

        /// <summary>
        /// 压缩
        /// </summary>
        /// <param name="files">待压缩文件</param>
        /// <returns>内存流</returns>
        public static MemoryStream Compression(List<string> files)
        {
            return Instance.Compression(files);
        }

        /// <summary>
        /// 压缩
        /// </summary>
        /// <param name="files">待压缩文件</param>
        /// <param name="zipPath">zip文件路径</param>
        public static void Compression(List<string> files, string zipPath)
        {
            Instance.Compression(files, zipPath);
        }

        /// <summary>
        /// 提取Zip文件
        /// </summary>
        /// <param name="zipPath">压缩文件路径</param>
        /// <param name="extractPath">提取路径</param>
        public static void Extract(string zipPath, string extractPath)
        {
            Instance.Extract(zipPath, extractPath);
        }
    }
}
